$(document).ready(function(){
    $('.playiconlist').hover(function(){
        $('.playicon').show();
    },function(){
        $('.playicon').hide();
    })
    $('.playicon').hover(function(){
        $(this).show()
    },function(){
        $(this).hide()
    })
    function a(a) {
        var b = new Array();
        return b["tudou"] = "土豆", b["yuku"] = "优酷", b["qiyi"] = "爱奇艺", b["letv"] = "乐视", 
        b["sohu"] = "搜狐", b["pptv"] = "聚力", b["qq"] = "腾讯", b["letvyun"] = "乐视云", b["bilibili"] = "哔哩哔哩", 
        b["acfun"] = "A站", b["other"] = "其他", b[a];
    }

    if (1 === setting && "" != ff_urls) {
        var data = JSON.parse(ff_urls).Data, html = '', vid, name, type, list = $('.playicon span');
        for (var e = 0; e < data.length; e++) {
            vid = vod_pid <= data[e].playurls.length && data[e].playurls[parseInt(vod_pid) - 1][1];
            if(vid){
                type = data[e].playname;
                name = a(type);
                for(var i = 0; i < list.length; i++){
                    if(name === list.eq(i).text()){
                        if(list.eq(i).hasClass('current')){
                            html += '<span class="elm bf current" data-type="' + type + '" data-vid="' + vid + '"><i class="'+ type +'"></i>' + (name === '哔哩哔哩' ? 'B站' : name) + "</span>";
                        }else{
                            html += '<span class="elm bf" data-type="' + type + '" data-vid="' + vid + '"><i class="'+ type +'"></i>' +  (name === '哔哩哔哩' ? 'B站' : name) + "</span>";
                        }
                    } 
                }
            }
        }
        $('.playicon').html('');
        $(".playicon").html(html);
        $('.playiconlist i').attr('class', $('.playicon .current').attr('data-type'));
        var text = localStorage.text = $('.playicon .current').text() === '哔哩哔哩' ? 'B站' : $('.playicon .current').text()
        $('.playiconlist em').text(text);
    }
   
    //点击切换播放源vod_pid cur
    $('.playicon span').click(function(){
        var type = $(this).attr('data-type'),
            vid = $(this).attr("data-vid"),
            text = $(this).text();
        $('.playiconlist i').attr('class', type);
        $('.playiconlist em').text(text);
        $('.tab-main').hide();
        $('#' + type).find('a').eq(vod_pid - 1).addClass('cur');
        $('#' + type).show();
        if(!(text === localStorage.text)){
            (type && vid) && Play(vid, type)
            localStorage.text = $(this).text();
        }
    })

    var $cura = $('.sub-main a.cur');
    if($('.sub-main a').hasClass('cur')){
        var posi=$cura.position();
        $(".tab-main").animate({scrollTop:posi.top},200);
    }
});